package physics.body;

import physics.PMatrix;
import physics.PVector;

/**
 *
 * @author peter
 */
public class Rect extends Shape {
	public static final double DEFAULT_SIZE = 50.0;
	private PVector size;
	private PVector topLeft;
	private PVector topRight;
	private PVector bottomLeft;
	private PVector bottomRight;

	public PVector getSize()
	{
		return size;
	}

	public Rect()
	{
		this(0, 0, DEFAULT_SIZE, DEFAULT_SIZE);
	}

	public Rect(double xPos, double yPos, double width, double height)
	{
		collisionPoint = new PVector();
		size = new PVector(width, height);
		position = new PVector(xPos, yPos);
		topLeft = new PVector(0, 0);
		topRight = new PVector(width, 0);
		bottomLeft = new PVector(0, height);
		bottomRight = new PVector(width, height);
		boundingBox = new PMatrix(xPos, yPos, xPos + width, yPos + height);
	}

	public PVector[] getPoints()
	{
		updatePoints();
		return new PVector[]{topLeft, topRight, bottomRight, bottomLeft};
	}

	public void updatePoints()
	{
		PMatrix r = new PMatrix(rotation);
		PVector h = getSize().getScale(0.5);

		bottomLeft = r.mul(new PVector(-h.getX(), -h.getY()));
		bottomLeft.add(position);
		bottomRight = r.mul(new PVector(h.getX(), -h.getY()));
		bottomRight.add(position);
		topRight = r.mul(new PVector(h.getX(), h.getY()));
		topRight.add(position);
		topLeft = r.mul(new PVector(-h.getX(), h.getY()));
		topLeft.add(position);
	}

	public void collisionOccured()
	{
//		color = new Color((int) (Math.random() * 255.0), (int) (Math.random() * 255.0),(int) (Math.random() * 255.0));
	}

	@Override
	public double getOneOverCMMomentOfInnertia()
	{
		return 1.0 / ((mass/6) * (size.getX() * size.getX() + size.getY() * size.getY()) *2);
	}
}
